<?php

App::uses('Controller', 'Controller');
App::uses('SzamlaSzamSQL', 'Lib/Utility');

class SzamlaSzamSQLTest extends CakeTestCase {
	public $SzamlaSzamSQL = null;

	public function setUp() {
		parent::setUp();
		$this->SzamlaSzamSQL = new SzamlaSzamSQL();
	}

		public function testCreateSzamlaTartomanySql(){

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('91', 'left');
		$expected = 'LEFT(szamlak.szam, 2) = "91"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('91*');
		$expected = 'szamlak.szam BETWEEN "91" AND "919999999999"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('91*', 'left');
		$expected = 'LEFT(szamlak.szam, 2) = "91"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('91*');
		$expected = 'szamlak.szam BETWEEN "91" AND "919999999999"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('5145*');
		$expected = 'szamlak.szam BETWEEN "5145" AND "51459999999999"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('5145*', 'left');
		$expected = 'LEFT(szamlak.szam, 4) = "5145"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('96*+99*');
		$expected = 'szamlak.szam BETWEEN "96" AND "969999999999" OR szamlak.szam BETWEEN "99" AND "999999999999"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('96*+99*', 'left');
		$expected = 'LEFT(szamlak.szam, 2) = "96" OR LEFT(szamlak.szam, 2) = "99"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('1*+23*+3*', 'left');
		$expected = 'LEFT(szamlak.szam, 1) = "1" OR LEFT(szamlak.szam, 2) = "23" OR LEFT(szamlak.szam, 1) = "3"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('9*-96*');
		$expected = 'szamlak.szam BETWEEN "9" AND "969999999999"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('161*-1623*');
		$expected = 'szamlak.szam BETWEEN "161" AND "16239999999999"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('1*-2*+3*-4*+5*', 'left');
		$expected = 'szamlak.szam BETWEEN "1" AND "29999999999" OR szamlak.szam BETWEEN "3" AND "49999999999" OR LEFT(szamlak.szam, 1) = "5"';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('9*-96*+99*', 'left');
		$expected = 'szamlak.szam BETWEEN "9" AND "969999999999" OR LEFT(szamlak.szam, 2) = "99"';
		$this->assertEquals($expected, $actual);
		
		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('5*-869*+9*-969*!869+867', 'left');
		$expected = '(szamlak.szam BETWEEN "5" AND "8699999999999" OR szamlak.szam BETWEEN "9" AND "9699999999999") AND (LEFT(szamlak.szam, 3) != "869" AND LEFT(szamlak.szam, 3) != "867")';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('5*-969*!867+8691+87*-88*', 'left');
		$expected = '(szamlak.szam BETWEEN "5" AND "9699999999999") AND (LEFT(szamlak.szam, 3) != "867" AND LEFT(szamlak.szam, 4) != "8691" AND szamlak.szam NOT BETWEEN "87" AND "889999999999")';
		$this->assertEquals($expected, $actual);

		$actual = $this->SzamlaSzamSQL->createSzamlaTartomanySql('5*-53*+814*!517*', 'left');
		$expected = '(szamlak.szam BETWEEN "5" AND "539999999999" OR LEFT(szamlak.szam, 3) = "814") AND (LEFT(szamlak.szam, 3) != "517")';
		$this->assertEquals($expected, $actual);
	}
}
?>